﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _channeledit1 : JumbotCms.API.AdminCenter
    {
        public string _isout = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            ChannelId = Str2Str(q("ccid"));
            id = Str2Str(q("id"));
            Admin_Load("000000", "html", false);
            this.txtEditor1.BasePath = site.Dir + "editors/114editor/";
            Jumbot.DataOper.WebFormHandler wh = new Jumbot.DataOper.WebFormHandler(doh, "jcms_normal_channel", btnSave);
            wh.AddBind(txtTitle, "Title", true);
            wh.AddBind(txtEditor1, "Value", "Info", true);
            wh.AddBind(ddlClassDepth, "ClassDepth", false);
            wh.AddBind(txtDir, "Dir", true);
            wh.AddBind(txtOutUrl, "OutUrl", true);
            wh.AddBind(rblTarget, "SelectedValue", "Target", false);
            wh.AddBind(rblEnabled, "SelectedValue", "Enabled", false);
            if (ChannelId != "0")
            {
                wh.ConditionExpress = "id=" + ChannelId;
                wh.Mode = Jumbot.DataOper.OperationType.Modify;
                this.ddlClassDepth.Enabled = false;
            }
            else
            {
                wh.Mode = Jumbot.DataOper.OperationType.Add;
            }
            wh.validator = chkForm;
            wh.BindBeforeModifyOk += new EventHandler(bind_ok);
            wh.AddOk += new EventHandler(add_ok);
            wh.ModifyOk += new EventHandler(save_ok);
        }
        protected void bind_ok(object sender, EventArgs e)
        {
        }
        protected bool chkForm()
        {
            if (!CheckFormUrl())
                return false;
            if (!Page.IsValid)
                return false;
            doh.Reset();
            doh.ConditionExpress = "Title=@title and id<>" + ChannelId;
            doh.AddConditionParameter("@title", txtTitle.Text);
            if (doh.Exist("jcms_normal_channel"))
            {
                FinalMessage("频道名重复!", "", 1);
                return false;
            }
            return true;
        }
        protected void add_ok(object sender, EventArgs e)
        {
            doh.Reset();
            doh.ConditionExpress = "id>0 ORDER BY pId desc";
            int pId = Jumbot.Common.Validator.StrToInt(doh.GetValue("jcms_normal_channel", "pId").ToString(), 0);
            doh.Reset();
            doh.ConditionExpress = "Title=@title";
            doh.AddConditionParameter("@title", txtTitle.Text);
            doh.AddFieldItem("pId", pId + 1);
            doh.AddFieldItem("TemplateId", 0);
            doh.AddFieldItem("Type", "system");
            doh.AddFieldItem("IsOut", 1);
            doh.AddFieldItem("IsPost", 0);
            doh.AddFieldItem("IsNav", 0);
            doh.AddFieldItem("IsHtml", 0);
            doh.AddFieldItem("DefaultThumbs", 0);
            doh.Update("jcms_normal_channel");
            FinalMessage("频道成功保存", site.Dir + "admin/close.htm", 0);
        }
        protected void save_ok(object sender, EventArgs e)
        {
            FinalMessage("频道成功保存", site.Dir + "admin/close.htm", 0);
        }
    }
}
